package com.eric.webproject.controller;

import cn.hutool.core.text.StrMatcher;
import cn.hutool.core.util.StrUtil;
import com.eric.webproject.model.TestModel;
import com.eric.webproject.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping("/test")
    @ResponseBody
    public void test(TestModel testModel) {
        System.out.println(testService.selectByName(testModel.getName()));
    }

    @RequestMapping("/begin")
    public String begin(){
        return "test/main";
    }

    @RequestMapping("/index")
    public String index(){
        return "index";
    }

    @RequestMapping("/main1.html")
    public String main1(){
        return "test/main1";
    }

    @PostMapping("/common/login")
    @ResponseBody
    public String login(@RequestBody TestModel testModel){
        if(StrUtil.isBlank(testModel.getName()) || StrUtil.isBlank(testModel.getPass())){
            return "请填写完整！";
        }
        TestModel testModel1 = testService.selectByName(testModel.getName());
        if(!testModel.getPass().equals(testModel1.getPass())){
            return "账号或密码错误！";
        }
        return "登录成功！";
    }
}
